package org.example.kg_back.service.imp;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.kg_back.PoJo.entity.Company;
import org.example.kg_back.mapper.CompanyMapper;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class CompanyService extends ServiceImpl<CompanyMapper, Company> {

	/**
	 * 查询指挥航空公司航班数，和航班延误数
	 */
	public List<Company> findCompanyDelay() {
		List<Company> companyDelay = baseMapper.findCompanyDelay();

		for (Company c : companyDelay) {
			double dcount = Double.parseDouble(c.getDelayCount());
			double count = Double.parseDouble(c.getCount());
			Double rest = dcount / count * 100;
			c.setDelayCount(String.format("%.2f", rest));
		}

		return companyDelay;
	}


	/**
	 * 查询指挥航空公司占比
	 */
	public List<Company> findCompanyByCompanyAll() {
		List<Company> companyDelay = baseMapper.findCompanyDelay();
		double sum = 0;
		for (Company c : companyDelay) {
			double count = Double.parseDouble(c.getCount());
			sum+=count;
		}
		for (Company c : companyDelay) {
			double count = Double.parseDouble(c.getCount());
			c.setCompanyCount((count!=0)?sum/count:0);
		}
		return companyDelay;
	}

	/**
	 * 机场负荷统计
	 */
	public List<Company> findAirportCount(){
		List<Company> companyDelay = baseMapper.findCompanyDelay();
		double sum = 0;
		for (Company c : companyDelay) {
			double count = Double.parseDouble(c.getCount());
			sum+=count;
		}
		for (Company c : companyDelay) {
			double count = Double.parseDouble(c.getCount());
			c.setCompanyCount((count!=0)?sum/count:0);
		}
		return companyDelay;
	}

}
